<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @filename madv.php
 * 新闻公告模型
 * @author hmw
 *
 */

class Madv extends Model {

    function Madv() {
        parent::Model();
    }
    
    function get_adv_list(){
    	$query = $this->db->get('index_adv');
    	return $query->result_array();
    }
    
    function get_index_adv(){
    	$query = $this->db->get('index_adv');
    	$res = $query->result_array();
    	$array = array();
    	foreach($res as $arr){
    		$array[$arr['adv_name']] = $arr;
    	}
    	return $array;
    }
    
    function insert_new_adv($values){
    	return $this->db->insert('index_adv',$values);
    }
    
    function get_adv_info($id){
    	$query = $this->db->get_where('index_adv',array('id'=>$id));
    	return $query->row_array();
    }
    
    function update_adv_info($id,$values){
    	return $this->db->update('index_adv',$values,array('id'=>$id));
    }
    
    function update_adv_state($id,$state=1){
    	return $this->db->update('index_adv',array('adv_state'=>$state),array('id'=>$id));
    }
    
    function delete_adv($id){
    	return $this->db->delete('index_adv',array('id'=>$id));
    }
    
    function get_active_adv(){
    	$this->db->order_by('id','desc');
    	$this->db->limit(1);
    	$query = $this->db->get_where('index_adv',array('adv_state'=>1));
    	return $query->row_array();
    }
    
}

?>